package com.ult.util;

import java.text.MessageFormat;
import java.util.ResourceBundle;

public class Bundle {
	
	private static final String BUNDLE = "Bundle";
	private static final String SYSTEM_BUNDLE = "SystemBundle";
	private static final String FCO_BUNDLE = "FCOBundle";
	private static final String SOLICITACAO_EXAME_BUNDLE = "SolicitacaoExameBundle";
	private static final String PERIODO_SEMESTRAL ="BundlePeriodoSemestral";
	
	
	private static ResourceBundle bundle;
	private static ResourceBundle systemBundle;
	private static ResourceBundle fcoBundle;
	private static ResourceBundle solicitacaoExameBundle;
	private static ResourceBundle periodoSemestral;
	
	private static ResourceBundle getBundle() {
		if(bundle == null)
			bundle = ResourceBundle.getBundle(BUNDLE);
		return bundle;
	}
	
	private static ResourceBundle getSystemBundle() {
		if(systemBundle == null)
			systemBundle = ResourceBundle.getBundle(SYSTEM_BUNDLE);
		return systemBundle;
	}
	
	private static ResourceBundle getFCOBundle() {
		if(fcoBundle == null)
			fcoBundle = ResourceBundle.getBundle(FCO_BUNDLE);
		return fcoBundle;
	}

	private static ResourceBundle getSolicitacaoExameBundle() {
		if(solicitacaoExameBundle == null)
			solicitacaoExameBundle = ResourceBundle.getBundle(SOLICITACAO_EXAME_BUNDLE);
		return solicitacaoExameBundle;
	}
	
	public static ResourceBundle getPeriodoSemestral() {
		if(periodoSemestral == null)
			periodoSemestral = ResourceBundle.getBundle(PERIODO_SEMESTRAL); // NOI18N
		return periodoSemestral;
	}

	
	public static String getString(String name){
		try {
			if(getBundle().containsKey(name)){
				return getBundle().getString(name);
			}
			if(getSystemBundle().containsKey(name)){
				return getSystemBundle().getString(name);
			}
			if(getFCOBundle().containsKey(name)){
				return getFCOBundle().getString(name);
			}
			if(getSolicitacaoExameBundle().containsKey(name)){
				return getSolicitacaoExameBundle().getString(name);
			}
			if(getPeriodoSemestral().containsKey(name)){
				return getPeriodoSemestral().getString(name);
			}
			return name;
		} catch (Exception e) {
			return name;
		}
	}
	
	public static String getString(String name, Object...parametros){
		String result = getString(name);

		MessageFormat ms = new MessageFormat(result);

		return ms.format(parametros);
	}
	

}
